We show how to assign to any immersed torus in $\R^3$ or $S^3$ a Riemann surface such that the immersion is described by functions defined on this surface. We call this surface the spectrum or the spectral curve of the torus. The spectrum contains important information about conformally invariant properties of the torus and, in particular, relates to the Willmore functional. We propose a simple proof that for isothermic tori in $\R^3$ (this class includes constant mean curvature tori and tori of revolution) the spectrum is invariant with respect to conformal transformations of $\R^3$. We show that the spectral curves of minimal tori in $S^3$ introduced by Hitchin and of constant mean curvature tori in $\R^3$ introduced by Pinkall and Sterling are particular cases of this general spectrum. The construction is based on the Weierstrass representation of closed surfaces in $\R^3$ and the construction of the Floquet--Bloch varieties of periodic differential operators.